//#include "lua/lua.hpp"

#include "Common.h"
#include "ScriptVM.h"

#include "Binds.h"

namespace ScriptVM
{
	static lua_State* luaVM = NULL;
	
	bool init()
	{
		if ((luaVM = luaL_newstate()) == NULL)
		{
			LOG_ERROR("Can't initialize ScriptVM\n");
			return false;
		}
		
		luaL_openlibs(luaVM);
		
		Binds::bindGame(luaVM);
		Binds::bindRender(luaVM);
		
		return true;
	}
	
	void free()
	{
		lua_close(luaVM);
	}
	
	bool doFile(const char *name)
	{
		if (luaL_dofile(luaVM, name) == 0)
			return true;
		
		LOG_ERROR("Can't execute script '%s': %s\n", name, lua_tostring(luaVM, -1));
		return false;
	}
}
